#!/bin/sh /etc/rc.common
#
#

START=99
STOP=10

BIN=/usr/bin/wifidog-ng

parse_whitelist_mac() {
    local cfg="$1"
    local mac

    uci_validate_section wifidog-ng whitelist "${1}" \
        'mac:macaddr'

    [ $? -ne 0 ] && {
        echo "validation whitelist_mac failed" >&2
        exit 1
    }
}

parse_whitelist_domain() {
    local cfg="$1"
    local domain

    uci_validate_section wifidog-ng whitelist "${1}" \
        'domain:host'

    [ $? -ne 0 ] && {
        echo "validation whitelist_domain failed" >&2
        exit 1
    }
}

get_config() {
    config_get_bool vt_enabled $1 enabled 0
}

start() {
    config_load wifidog-ng
    config_foreach get_config gateway

    if [ "$vt_enabled" = 0 ]; then
        echo "WARNING: WifiDog-ng is disabled."
        exit 0
    fi

    #config_foreach parse_whitelist_mac whitelist_mac
    #config_foreach parse_whitelist_domain whitelist_domain

    modprobe wifidog-ng

    $BIN & >/dev/null &
}

stop() {
    rmmod wifidog-ng
    killall -9 wifidog-ng 2>/dev/null
}
